import { ShopOrderFees } from './shopOrderFee';
let _ShopOrderFees = ShopOrderFees;
/**
 * 拷贝下面两行到 mock/index.js中,即可支持客户端虚拟数据、免服务端连接
 * import ShopOrderFeeMock from './mk/mng/computed/day/shopOrderFeeMock';
 * ShopOrderFeeMock.bootstrap(mock);
 */
export default {
  /**
   * mock bootstrap
   */
  bootstrap(mock) {    
  
    //获取列表 模糊查询、根据关键字查询
    mock.onGet('/mk/mng/computed/day/shopOrderFee/listKey').reply(config => {
      let params = config.params;
      let mockShopOrderFees = _ShopOrderFees.filter(shopOrderFee => {
      	if(params.totalPrice||params.totalPrice==''){ if( shopOrderFee.totalPrice.indexOf(params.totalPrice)>=0) return true;}
      	if(params.totalFee||params.totalFee==''){ if( shopOrderFee.totalFee.indexOf(params.totalFee)>=0) return true;}
      	if(params.shopId||params.shopId==''){ if( shopOrderFee.shopId.indexOf(params.shopId)>=0) return true;}
      	if(params.shopName||params.shopName==''){ if( shopOrderFee.shopName.indexOf(params.shopName)>=0) return true;}
      	if(params.id||params.id==''){ if( shopOrderFee.id.indexOf(params.id)>=0) return true;}
      	if(params.orderCount||params.orderCount==''){ if( shopOrderFee.orderCount.indexOf(params.orderCount)>=0) return true;}
      	if(params.goodsCount||params.goodsCount==''){ if( shopOrderFee.goodsCount.indexOf(params.goodsCount)>=0) return true;}
      	if(params.custCount||params.custCount==''){ if( shopOrderFee.custCount.indexOf(params.custCount)>=0) return true;}
      	if(params.bizDate||params.bizDate==''){ if( shopOrderFee.bizDate.indexOf(params.bizDate)>=0) return true;}
      	if(params.startComputedDate||params.startComputedDate==''){ if( shopOrderFee.startComputedDate.indexOf(params.startComputedDate)>=0) return true;}
      	if(params.computedStatus||params.computedStatus==''){ if( shopOrderFee.computedStatus.indexOf(params.computedStatus)>=0) return true;}
      	if(params.productNums||params.productNums==''){ if( shopOrderFee.productNums.indexOf(params.productNums)>=0) return true;}
        return false;
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            data: mockShopOrderFees
          }]);
        }, 1000);
      });
    });
    
    

    //获取列表（分页/不分页）
    mock.onGet('/mk/mng/computed/day/shopOrderFee/list').reply(config => {
      let params = config.params;
      let mockShopOrderFees = _ShopOrderFees.filter(shopOrderFee => {
      	var isTrue=false;
      	if(params.totalPrice||params.totalPrice==''){if(shopOrderFee.totalPrice.indexOf(params.totalPrice)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.totalFee||params.totalFee==''){if(shopOrderFee.totalFee.indexOf(params.totalFee)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.shopId||params.shopId==''){if(shopOrderFee.shopId.indexOf(params.shopId)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.shopName||params.shopName==''){if(shopOrderFee.shopName.indexOf(params.shopName)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.id||params.id==''){if(shopOrderFee.id.indexOf(params.id)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.orderCount||params.orderCount==''){if(shopOrderFee.orderCount.indexOf(params.orderCount)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.goodsCount||params.goodsCount==''){if(shopOrderFee.goodsCount.indexOf(params.goodsCount)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.custCount||params.custCount==''){if(shopOrderFee.custCount.indexOf(params.custCount)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.bizDate||params.bizDate==''){if(shopOrderFee.bizDate.indexOf(params.bizDate)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.startComputedDate||params.startComputedDate==''){if(shopOrderFee.startComputedDate.indexOf(params.startComputedDate)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.computedStatus||params.computedStatus==''){if(shopOrderFee.computedStatus.indexOf(params.computedStatus)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.productNums||params.productNums==''){if(shopOrderFee.productNums.indexOf(params.productNums)>=0){isTrue=true;}else{isTrue=false;}}
      	return isTrue;
	  });
      if(!config.params.currentPage){ 
	      return new Promise((resolve, reject) => {
	        setTimeout(() => {
	          resolve([200, {
	            data: mockShopOrderFees
	          }]);
	        }, 1000);
	      });
      }
    
      let {pageSize,currentPage, total} = config.params;
      total = mockShopOrderFees.length;
      mockShopOrderFees = mockShopOrderFees.filter((shopOrderFee, index) => index < pageSize * currentPage && index >= pageSize * (currentPage - 1));
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            pageInfo: {
            	total:total
            },
            data: mockShopOrderFees,
            tips:{
            	isOk:true,
            	msg:'查询成功'
            }
          }]);
        }, 1000);
      });
    });

    //删除
    mock.onPost('/mk/mng/computed/day/shopOrderFee/del').reply(config => {
      var params = JSON.parse( config.data );
      let {  id  } = params;
      _ShopOrderFees = _ShopOrderFees.filter(shopOrderFee => shopOrderFee.id !== id);
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'删除成功'
            }
          }]);
        }, 500);
      });
    });

    //批量删除
    mock.onPost('/mk/mng/computed/day/shopOrderFee/batchDel').reply(config => {
      var params = JSON.parse( config.data );
      _ShopOrderFees = _ShopOrderFees.filter(shopOrderFee => !params.includes(shopOrderFee.id));
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
           tips:{
            	isOk:true,
            	msg:'删除成功'
            }
          }]);
        }, 500);
      });
    });

    //编辑
    mock.onPost('/mk/mng/computed/day/shopOrderFee/edit').reply(config => {
      var params = JSON.parse( config.data );
      let { totalPrice,totalFee,shopId,shopName,id,orderCount,goodsCount,custCount,bizDate,startComputedDate,computedStatus,productNums } = params;
      _ShopOrderFees.some(shopOrderFee => {
        if (shopOrderFee.id === id) {
			shopOrderFee.totalPrice = totalPrice;
			shopOrderFee.totalFee = totalFee;
			shopOrderFee.shopId = shopId;
			shopOrderFee.shopName = shopName;
			shopOrderFee.id = id;
			shopOrderFee.orderCount = orderCount;
			shopOrderFee.goodsCount = goodsCount;
			shopOrderFee.custCount = custCount;
			shopOrderFee.bizDate = bizDate;
			shopOrderFee.startComputedDate = startComputedDate;
			shopOrderFee.computedStatus = computedStatus;
			shopOrderFee.productNums = productNums
          return true;
        }
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'编辑成功'
            }
          }]);
        }, 500);
      });
    });

    //新增
    mock.onPost('/mk/mng/computed/day/shopOrderFee/add').reply(config => {
      var params = JSON.parse( config.data );
      let { totalPrice,totalFee,shopId,shopName,id,orderCount,goodsCount,custCount,bizDate,startComputedDate,computedStatus,productNums } = params;
      _ShopOrderFees.push({
		totalPrice:totalPrice,
		totalFee:totalFee,
		shopId:shopId,
		shopName:shopName,
		id:id,
		orderCount:orderCount,
		goodsCount:goodsCount,
		custCount:custCount,
		bizDate:bizDate,
		startComputedDate:startComputedDate,
		computedStatus:computedStatus,
		productNums:productNums
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'新增成功'
            }
          }]);
        }, 500);
      });
    });

  }
};